/*
 * @Description: 行程详情(行程订单详情)   DetailsOfItineraryOrders
 * @version: 
 * @Company: 
 * @Author: ZhengZhuang
 * @Date: 2019-08-28 14:12:53
 * @LastEditors: zhengzhuang
 * @LastEditTime: 2020-08-04 10:03:28
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/provider/order_information.dart';
import 'package:C20Driver/service/request.dart';
import 'package:C20Driver/utils/utils.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:provider/provider.dart';

class DetailsOfItineraryOrders extends StatefulWidget {
  final String orderId;
  DetailsOfItineraryOrders({this.orderId});
  @override
  _DetailsOfItineraryOrdersState createState() =>
      _DetailsOfItineraryOrdersState();
}

class _DetailsOfItineraryOrdersState extends State<DetailsOfItineraryOrders> {
  @override
  void initState() {
    super.initState();

    _getOrderInfo();
  }

  /// 获取订单信息
  void _getOrderInfo() {
    Request.getOrderInfo(context: context, orderId: widget.orderId);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('行程详情'),
      ),
      body: Container(
        child: Column(
          children: <Widget>[
            Expanded(
              child: Container(
                padding: EdgeInsets.all(ScreenUtil().setWidth(20.0)),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text('本次行程'),
                    _detailsCard(),
                  ],
                ),
              ),
            ),
            InkWell(
              child: Container(
                width: ScreenUtil().setWidth(750.0),
                height: ScreenUtil().setWidth(120.0),
                color: Color.fromARGB(255, 147, 155, 166),
                alignment: Alignment.center,
                child: Text(
                  '取消订单',
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(36.0),
                    color: Colors.white,
                  ),
                ),
              ),
              onTap: () => NavigatorUtil.jump(
                  context, '/cancellationOrder?orderId=${widget.orderId}'),
            )
          ],
        ),
      ),
    );
  }

  // 行程卡片
  Widget _detailsCard() {
    return Container(
      child: Card(
        child: Column(
          children: <Widget>[
            Container(
              height: ScreenUtil().setWidth(150.0),
              padding: EdgeInsets.only(
                left: ScreenUtil().setWidth(30.0),
              ),
              decoration: BoxDecoration(
                  border: Border(
                      bottom: BorderSide(
                width: ScreenUtil().setWidth(1.0),
                color: Color.fromARGB(255, 228, 228, 228),
              ))),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      ClipOval(child: Consumer<OrderInformation>(
                          builder: (ctx, state, child) {
                        return Image.network(
                          state.itineraryInfo.passengerHeadimgurl != null
                              ? state.itineraryInfo.passengerHeadimgurl
                              : '',
                          width: ScreenUtil().setWidth(80.0),
                          height: ScreenUtil().setWidth(80.0),
                          fit: BoxFit.cover,
                        );
                      })),
                      SizedBox(width: ScreenUtil().setWidth(20.0)),
                      Consumer<OrderInformation>(builder: (ctx, state, child) {
                        return Text(
                          '尾号${state.itineraryInfo.lastNum != null ? state.itineraryInfo.lastNum : ''}',
                          style: TextStyle(
                            fontSize: ScreenUtil().setSp(30.0),
                          ),
                        );
                      })
                    ],
                  ),
                  Row(
                    children: <Widget>[
                      // IconButton(
                      //   icon: Icon(Icons.chat),
                      //   onPressed: () =>
                      //       NavigatorUtil.jump(context, '/detailsMessage'),
                      // ),
                      Consumer<OrderInformation>(builder: (ctx, state, child) {
                        return IconButton(
                          icon: Icon(Icons.phone),
                          onPressed: () => Utils.callPhone(
                              state.itineraryInfo.passengerMobile),
                        );
                      }),
                    ],
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.all(ScreenUtil().setWidth(50.0)),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Container(
                        width: ScreenUtil().setWidth(15.0),
                        height: ScreenUtil().setWidth(15.0),
                        decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          color: Color.fromARGB(255, 36, 142, 247),
                        ),
                      ),
                      SizedBox(width: ScreenUtil().setWidth(20.0)),
                      Consumer<OrderInformation>(builder: (ctx, state, child) {
                        return Container(
                          width: ScreenUtil().setWidth(550.0),
                          child: Text(
                            state.itineraryInfo.depAre != null
                                ? state.itineraryInfo.depAre
                                : '', // 起点
                            style: TextStyle(
                              fontSize: ScreenUtil().setSp(32.0),
                            ),
                          ),
                        );
                      })
                    ],
                  ),
                  SizedBox(height: ScreenUtil().setWidth(60.0)),
                  Row(
                    children: <Widget>[
                      Container(
                        width: ScreenUtil().setWidth(15.0),
                        height: ScreenUtil().setWidth(15.0),
                        decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          color: Color.fromARGB(255, 255, 102, 0),
                        ),
                      ),
                      SizedBox(width: ScreenUtil().setWidth(20.0)),
                      Consumer<OrderInformation>(builder: (ctx, state, child) {
                        return Container(
                          width: ScreenUtil().setWidth(550.0),
                          child: Text(
                            state.itineraryInfo.destArea != null
                                ? state.itineraryInfo.destArea
                                : '',
                            style: TextStyle(
                              fontSize: ScreenUtil().setSp(32.0),
                            ),
                          ),
                        );
                      })
                    ],
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
